home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / comm / mail / YAT.lha / YAT / Install / Developer / dos_comp.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-30  |  2.6 KB  |  149 lines

  1. //$VER:Dos_Comp 1.4 (04.07.100)
  2. class dos_comp
  3. {
  4.     public:
  5.  
  6.     // Parts:
  7.     // none            ignored
  8.     // device        part before ':'                        1.x
  9.     // path            parts before last '/'                1.x
  10.     // drawer        parts between ':' and last '/'      1.x
  11.     // name            part after last '/'                  1.x
  12.     // extension    part after last '.'                  1.3
  13.     // noext        like name, but without extension    1.3
  14.  
  15.     enum part{none,device,drawer,path,name,extension,noext};
  16.  
  17.     static int        get(char* input,char* output, part chunk, int maxsize=255){
  18.         char*    out_start=output;
  19.         char*    in_start=input;
  20.         char*    last=0;
  21.  
  22.         switch (chunk){
  23.  
  24.             case device:
  25.             *output=*input;
  26.             do{
  27.                 output++;input++;
  28.                 *output=*input;}
  29.             while (*input != ':' && *input && --maxsize);
  30.             if (*input != ':') {*out_start=0;return 5;}
  31.             *(++output)=0;
  32.             break;
  33.  
  34.             case drawer:
  35.             while (*input!=':' && *input!='/' && *input) input++;
  36.             switch (*input){
  37.                 case ':':
  38.                 in_start = ++input;
  39.                 break;
  40.  
  41.                 case '/':
  42.                 input=in_start;
  43.                 break;
  44.  
  45.                 case 0:
  46.                 return 5;
  47.  
  48.                 default:
  49.                 break;}
  50.             // Continues to case path:
  51.  
  52.             case path:
  53.             while(*input){
  54.                 if ( *input=='/' || *input==':' ) last=input;
  55.                 input++;}
  56.             if (last){
  57.                 input=in_start;
  58.                 *output=*input;
  59.                 do{
  60.                     output++;input++;
  61.                     *output=*input;}
  62.                 while(input!=last && --maxsize);
  63.                 output++;
  64.                 *output=0;}
  65.             else{
  66.                 *out_start=0;
  67.                 return 5;}
  68.             break;
  69.  
  70.             case noext:
  71.             last=in_start;
  72.             // Skip dirs and remember start of filename
  73.             while(*input){
  74.                 if ( *input=='/' || *input==':' ) last=input+1;
  75.                 input++;}
  76.             input=last;
  77.  
  78.             // Copy name
  79.             while(*last && --maxsize){
  80.                 *output=*last;
  81.                 output++;last++;}
  82.             *output=0;
  83.  
  84.             // Remove extension
  85.             while (output!=input)
  86.                 {
  87.                 switch (*output)
  88.                     {
  89.                     case '.':
  90.                     *output=0;
  91.                     output=input;
  92.                     break;
  93.  
  94.                     case ':':
  95.                     case '/':
  96.                     output=input;
  97.                     break;
  98.  
  99.                     default:
  100.                     output--;
  101.                     break;
  102.                     }
  103.                 }
  104.             break;
  105.  
  106.             case name:
  107.             last=in_start;
  108.             while(*input){
  109.                 if ( *input=='/' || *input==':' ) last=input+1;
  110.                 input++;}
  111.             while(*last && --maxsize){
  112.                 *output=*last;
  113.                 output++;last++;}
  114.             *output=0;
  115.             break;
  116.  
  117.             case extension:
  118.             //Find end
  119.             while (*input) input++;
  120.             //Rewind to a '.' ':' or '/'
  121.             int    loop=1;
  122.             while (loop && input!=in_start)
  123.                 {
  124.                 switch (*input)
  125.                     {
  126.                     // Extension found
  127.                     case '.':
  128.                     input++;
  129.                     while (int(*(output++)=*(input++)) && --maxsize);
  130.                     loop=0;
  131.                     break;
  132.  
  133.                     // No extension found
  134.                     case '/':
  135.                     case ':':
  136.                     loop=0;
  137.                     break;
  138.  
  139.                     default:
  140.                     input--;
  141.                     break;
  142.                     }
  143.                 }
  144.             break;
  145.             }
  146.         return 0;
  147.         }
  148. };
  149.